package com.dt.common.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 异常相关
 *
 * @author <a href ='jiaoxuhui@dhcc.com.cn'>焦旭辉</a>
 * @date 2019/10/11
 * @since JDK 1.8
 */
public class ExceptionPrintUtil {
    private final static Logger LOGGER = LoggerFactory.getLogger(ExceptionPrintUtil.class);

    /**
     * 打印堆栈跟踪 信息
     *
     * @param throwable 异常
     * @return 完整的堆栈跟踪信息
     */
    public static String stackLogRecord(Throwable throwable) {
        StringWriter stringWriter = new StringWriter();
        throwable.printStackTrace(new PrintWriter(stringWriter, true));
        LOGGER.error(stringWriter.getBuffer().toString());
        return stringWriter.getBuffer().toString();
    }
}

